'''
stat on my testdata
'''

import os.path as osp
import os
import numpy as np

def walkon(mainDir, fileExt='jpg'):
    '''
    mainDir consisting of many subfolders, 
    where each consisting of many images
    '''
    clsDict = {}
    clsNumDict  = {}
    for subdirName in sorted(os.listdir(mainDir)):
        subdir  = osp.join(mainDir, subdirName)
        if osp.isdir(subdir):
            tmpList = []
            for fileName in sorted(os.listdir(subdir)):
                if fileName.endswith('.'+fileExt):
                    tmpList.append(fileName)
            clsDict[subdirName] = tmpList
            clsNumDict[subdirName] = len(tmpList)
    return clsDict, clsNumDict

if __name__ == "__main__":
    train_dir= osp.dirname(osp.dirname(osp.abspath(__file__)))
    mainDir = osp.join(train_dir, 'data/my_testData-112X96')
    clsDict, clsNumDict = walkon(mainDir)
    clsNumArr  = np.array(clsNumDict.values())
    clsKeyList = clsNumDict.keys()
    print('cls:{} min number is: {}'.format(clsKeyList[np.argmin(clsNumArr)], np.amin(clsNumArr)))
    print('cls:{} max number is: {}'.format(clsKeyList[np.argmax(clsNumArr)], np.amax(clsNumArr)))
    print('cls mean number is: {}'.format(np.mean(clsNumArr)))
    print('cls median number is: {}'.format(np.median(clsNumArr)))
